#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>


//程序替换接口的初认识

int main()
{
    printf("I am a process, pid: %d\n", getpid());
    
    pid_t id = fork();
    if(id == 0)
    {
        printf("exec begin...\n");
        // execvp("ls", argv);        //数组+无路径
        //execv("/usr/bin/ls", argv); //数组 +有路径
        execl("/usr/bin/ls", "ls", "-a", "-l", NULL); //NULL 不是 "NULL"   //列表 + 路径
        //execlp("ls", "ls", "-a", "-l", NULL); //NULL 不是 "NULL"       //列表 +无路径
        //execl("/usr/bin/top", "/usr/bin/top", NULL); //NULL 不是 "NULL"
        printf("exec end ...\n");
        exit(1);
    }

    pid_t rid = waitpid(id, NULL, 0);
    if(rid > 0)
    {
        printf("wait success\n");
    }
    
    exit(1);
}

